package com.ruoyi.management.warning.controller;

import java.util.List;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.management.warning.ro.AddWarningHandleParam;
import com.ruoyi.management.warning.ro.GetWarningPageParam;
import com.ruoyi.management.warning.service.ITWarningService;
import com.ruoyi.management.warning.vo.GetWarningPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.validation.Valid;

/**
 * warningController
 * 
 * @author ruoyi
 * @date 2021-12-21
 */
@RestController
@Api(tags = "管理端告警管理")
@RequestMapping("/warning/warning")
public class TWarningController extends BaseController
{
    @Autowired
    private ITWarningService tWarningService;

    /**
     * 查询warning列表
     */
    @GetMapping("/list")
    @ApiOperation("查询告警列表")
    public TableDataInfo list(@Valid GetWarningPageParam param)
    {
        startPage();
        List<GetWarningPageVo> list = tWarningService.selectTWarningList(param);
        return getDataTable(list);
    }

    /**
     * 导出warning列表
     */
    @PreAuthorize("@ss.hasPermi('warning:warning:export')")
    @Log(title = "warning", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GetWarningPageParam param)
    {
        List<GetWarningPageVo> list = tWarningService.selectTWarningList(param);
        ExcelUtil<GetWarningPageVo> util = new ExcelUtil<GetWarningPageVo>(GetWarningPageVo.class);
        return util.exportExcel(list, "warning数据");
    }

    @PostMapping("/add-handle")
    @ApiOperation("处理告警")
    public AjaxResult addHandle(@Valid @RequestBody AddWarningHandleParam param)
    {
        return toAjax(tWarningService.addHandle(param,getLoginUser().getUserId()));
    }

}
